package org.datacoder.benchmark

import org.datacoder.geocoding.jurisdiction.*
import org.datacoder.util.*

/**
 * Stores statistics for a given finder.  Finder statistics
 * include startup time, average query time, and query times
 * by type of jurisdiction.  ResultHolder can initialize
 * FinderStatHolders with stored data from XML files, so
 * FinderStatHolders can hold data from multiple runs.  They
 * store both the raw data from each run and summary statistics
 * (means, etc.) in StatHolder objects.
 */
class FinderStatHolder {

    Class clazz
    int numRuns
    LinkedList<Double> startUpTimes
    LinkedList<Double> averageQueryTimes
    Map<Class, LinkedList<Double>> byJurisTimes

    // Transients
    StatHolder startUpStats
    StatHolder averageQueryStats
    Map<Class, StatHolder> byJurisStats

    public FinderStatHolder(Class clazz){
        this.clazz = clazz
        startUpTimes = new LinkedList<Double>()
        averageQueryTimes = new LinkedList<Double>()
        byJurisTimes = new TreeMap<Class, List<Double>>(new ClassNameComparator())
        List<Class> jurisClasses = new LinkedList<Class>()
        GeneralUtils.initializeClassList(GeneralUtils.JURISDICTION_PACKAGE, Jurisdiction, jurisClasses)
        for(jurisClass in jurisClasses){
            byJurisTimes.put(jurisClass, new LinkedList<Double>())
        }
        numRuns = 0
    }

    public void calculateStatistics(){
        startUpStats = new StatHolder(startUpTimes)
        averageQueryStats = new StatHolder(averageQueryTimes)
        byJurisStats = new TreeMap<Class, StatHolder>(new ClassNameComparator())
        for(jurisClass in byJurisTimes.keySet()){
            byJurisStats.put(jurisClass, new StatHolder(byJurisTimes.get(jurisClass)))
        }
    }

}

